home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / comm / tcp / AmigaTCP.lha / AmigaTCP / src / timer.h < prev    next >
C/C++ Source or Header  |  1989-06-24  |  1KB  |  31 lines

  1. /* Software timers
  2.  * There is one of these structures for each simulated timer.
  3.  * Whenever the timer is running, it is on a doubly-linked list
  4.  * pointed to by "timers" so that the (hardware) timer interrupt
  5.  * can quickly run through the list and change counts and states.
  6.  * Stopping a timer or letting it expire causes it to be removed
  7.  * from the list; starting a timer puts it on the list.
  8.  */
  9. struct timer {
  10.     struct timer *next;    /* Doubly-linked-list pointers */
  11.     struct timer *prev;
  12.     int16 start;        /* Period of counter (load value) */
  13.     int16 count;        /* Ticks to go until expiration */
  14.     void (*func)();        /* Function to call at expiration */
  15.     int *arg;        /* Arg to pass function */
  16.     char state;        /* Timer state */
  17. #define    TIMER_STOP    0
  18. #define    TIMER_RUN    1
  19. #define    TIMER_EXPIRE    2
  20. };
  21. #define    NULLTIMER    (struct timer *)NULL
  22. #define    MAX_TIME    (int16)65535    /* Max short integer */
  23. #ifndef    MSPTICK
  24. #define    MSPTICK        1000        /* Milliseconds per tick */
  25. #endif
  26. /* Useful user macros that hide the timer structure internals */
  27. #define    set_timer(t,x)    (((t)->start) = (x)/MSPTICK)
  28. #define    dur_timer(t)    ((t)->start)
  29. #define    read_timer(t)    ((t)->count)
  30. #define    run_timer(t)    (((t)->state == TIMER_RUN) ? 1 : 0)
  31.